package emulator.util;

import java.util.Observable;

public class SynchronizedFlag extends Observable {
	boolean value;
	
	public SynchronizedFlag() {
		value = false;
	}
	
	public synchronized void setValue(boolean new_value) {
		boolean has_changed = (value != new_value);
		value = new_value;
		notifyAll();
		if (has_changed)
			touch();
	}
	
	public synchronized void waitForValue(boolean target_value) throws InterruptedException {
		while (value != target_value)
			wait();
	}

	public void touch() {
		setChanged();
		notifyObservers(value);
	}

	public boolean getValue() {
		return value;
	}
}
